package com.cw.demo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cw.demo.api.dto.UserDto;
import com.cw.demo.converter.UserConverter;
import com.cw.demo.dao.mapper.UserMapper;
import com.cw.demo.dao.model.UserDo;
import com.cw.demo.mq.dto.SyncDataDto;
import com.cw.demo.mq.enums.EnumAction;
import com.cw.demo.service.UserService;

import cn.hutool.core.bean.BeanUtil;

/**
 * 用户业务实现
 *
 * @author chenw
 * @date 2021/7/27
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class UserServiceImpl extends ServiceImpl<UserMapper, UserDo> implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<UserDto> queryList(UserDto userDto) {
        return UserConverter.doList2DtoList(userMapper.selectList(UserConverter.buildWrapper(userDto)));
    }

    @Override
    public Page<UserDto> queryPage(UserDto userDto, Long pageNum, Long pageSize) {
        Page page = page(new Page<>(pageNum, pageSize), UserConverter.buildWrapper(userDto));
        page.setRecords(UserConverter.doList2DtoList(page.getRecords()));
        return page;
    }

    @Override
    public Boolean removeUser(UserDto userDto) {
        return remove(UserConverter.buildWrapper(userDto));
    }
}
